package com.qb.mobile.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;

import com.qb.mobile.R;
import com.qb.mobile.model.Phonebook;
import com.qb.mobile.ui.PSListItem;

/**
 * @author <a href="mailto:dangcongthanhtrung@gmail.com">dangtrung</a>
 * 
 * SystemPhonebookAdapter.java class
 *
 */
public class SystemPhonebookAdapter extends ArrayAdapter<Phonebook> {

	private Context context;
	private List<Phonebook> listPhonebook;

	public SystemPhonebookAdapter(Context context, 
			List<Phonebook> listPhonebook) {
		super(context, android.R.layout.simple_list_item_multiple_choice, listPhonebook);
		this.context = context;
		this.listPhonebook = listPhonebook;
	}

	@Override
	public int getCount() {
		return ((null != listPhonebook) ? listPhonebook.size() : 0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public Phonebook getItem(int position) {
		return ((null != listPhonebook) ? listPhonebook.get(position) : null);
	}

	public View getView(int position, View convertView, ViewGroup viewGroup) {
		PSListItem v;
		if (convertView == null) {
			v = (PSListItem) View.inflate(context, R.layout.system_phone_row, null);
		} else {
			v = (PSListItem) convertView;
		}
		Phonebook phonebook = listPhonebook.get(position);
		v.setPhoneBookInfo(phonebook);
		
		return v;

	}
}
